//index.js
//获取应用实例
var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url:app.setting.att_url,
		action:"/store.manage.myfee/",
		account:app.setting.account,
		pagetitle:'门店业绩',
		loading:true,
		page:1,
		keyword:'',
		op:''
	},
	onReady: function (){
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (){
		var page=this;
		wx.setNavigationBarTitle({'title':page.data.pagetitle});
		app.util.get(app.access,function(pagedata){
			pagedata.pay_types=pagedata.wxapppay_types;
			pagedata.post.pay_typeindex=0;
			this.data.op = pagedata.op
			pagedata.post=pagedata.post?pagedata.post:{}
			page.setData({
				pagedata:pagedata,
			});
			page.getlist(1);
		});
	},
	keyword:function(e){
		var the = this
		var pagedata = the.data.pagedata
		pagedata.params.keyword = e.detail.value
	},
	getlist:function(e){
		var the=this
		var page=the.data.page
		var pagedata=the.data.pagedata
		var isnodata = the.data.isnodata
		var data={}
		the.setData({
			loading:true,
		});
		if(e){
			if(e.currentTarget){
				data = e.currentTarget.dataset;
				pagedata.params.type=data.type
			}
			pagedata.list=[]
			page=1
			isnodata=false;
		}else{
			if(isnodata){
				the.setData({
					loading:false,
				});
				return false;
			}
		}
		app.util.get('jy_weishop/store.manage.myfee/feelist/&page='+page+'&type='+pagedata.params.type,function(res){
			if(res.list.length==0){
				the.setData({
					isnodata:true,
					'pagedata.list':pagedata.list,
					'pagedata.params.type':pagedata.params.type,
					loading:false,
				});
			}else{
				console.log(page);
				pagedata.list = pagedata.list.concat(res.list)
				page++
				the.setData({
					'pagedata.list':pagedata.list,
					'pagedata.params.type':pagedata.params.type,
					page:page,
					isnodata:isnodata,
					loading:false,
				});
			}
		});
	},
	//翻页
	onReachBottom: function () {
		var isnodata=this.data.isnodata
		var loading=this.data.loading
		if(!isnodata && !loading){
			this.getlist()
		}
	},
	showtixian:function(e){
		var the=this
		var pagedata=the.data.pagedata
		var data=e.currentTarget.dataset;
		var isstore=data.isstore;
		if(isstore==1 && pagedata.isadmin!=1){
			app.util.message('您不是该店店长，不能结算！','error');
			return false;
		}
		if(isstore==1){
			pagedata.data.tifee=pagedata.data.daifee;
		}else{
			pagedata.data.tifee=pagedata.data.mydaifee;
		}
		pagedata.showtixian=pagedata.showtixian?false:true;
		pagedata.post.feetype=0;
		pagedata.post.isstore=isstore;
		the.setData({
			'pagedata.post':pagedata.post,
			'pagedata.data':pagedata.data,
			'pagedata.showtixian':pagedata.showtixian,
		});
	},
	closetixian:function(){
		var the = this
		the.setData({
			'pagedata.showtixian':false,
		});
	},
	applytype:function(e){
		var the=this;
		var pagedata = this.data.pagedata
		var value=e.detail.value;
		var pay_type = pagedata.pay_types[value].key
		console.log(value);console.log(pay_type)
		the.setData({
			'pagedata.post.pay_type':pay_type,
			'pagedata.post.pay_typeindex':value,
		});
	},
	tixian:function(e){
		var the = this
		var value=e.detail.value;
		var pagedata = this.data.pagedata
		if(value.alipay != value.alipay1){
			app.util.msg('支付宝帐号不一致！');
			return false;
		}
		if(value.bankcard != value.bankcard1){
			app.util.msg('银行卡号不一致！');
			return false;
		}
		pagedata.post.wechat = value.wechat
		pagedata.post.fee = value.fee
		pagedata.post.bankname = value.bankname
		pagedata.post.realname = value.realname
		pagedata.post.alipay = value.alipay
		pagedata.post.alipay1 = value.alipay1
		pagedata.post.bankcard = value.bankcard
		pagedata.post.bankcard1 = value.bankcard1
		app.util.post('/store.manage.myfee/balance/',pagedata.post)
	},
  	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util[data.func](data.params);
	},
	click_tab:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util.tab(data.params);
	},
	formSubmit:function(event){
		var data=event.detail.value;
		app.util.post('post',data);
	}
});